import os
from moviepy.video.io.VideoFileClip import VideoFileClip


def get_video_info(video_path):
    """获取视频信息的工具函数"""
    video = VideoFileClip(video_path)
    info = {
        "duration": video.duration,
        "size": video.size,
        "fps": video.fps,
        "audio_codec": video.audio.reader.codec if video.audio and hasattr(video.audio.reader, 'codec') else None,
        "video_codec": video.reader.codec if hasattr(video.reader, 'codec') else None
    }
    
    # 添加文件大小信息
    if os.path.exists(video_path):
        info["file_size"] = os.path.getsize(video_path)
    
    video.close()
    return info


__all__ = ['get_video_info']